package com.hook.test;

import android.content.SharedPreferences;
import android.util.Log;
import android.widget.TextView;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;


public class TargetHook implements IXposedHookLoadPackage {
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        XposedBridge.log(lpparam.packageName);
        if (!lpparam.packageName.equals("com.ss.android.ugc.aweme")) {
            return;
        }
        XposedBridge.log("进入hook程序");

        findAndHookMethod(
                "com.hfdcxy.android.by.test.a", //要hook的包名+类名
                lpparam.classLoader, //classLoader固定
                "a", //要hook的方法名
               String.class,//方法参数 没有就不填
                new XC_MethodHook() {
                    @Override
                    //方法执行前执行
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        XposedBridge.log(param.args[0].toString());
                    }
                    //方法执行后执行,改方法的返回值一定要在方法执行完毕后更改
                    protected void afterHookedMethod(MethodHookParam param)
                            throws Throwable {
                        XposedBridge.log(param.getResult().toString());

                    }
                }
        );
        findAndHookMethod(
                "com.hfdcxy.android.by.test.b", //要hook的包名+类名
                lpparam.classLoader, //classLoader固定
                "a", //要hook的方法名
                SharedPreferences.class,
                TextView.class,
                int.class,//方法参数 没有就不填
                new XC_MethodHook() {
                    @Override
                    //方法执行前执行
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        XposedBridge.log("修改前"+param.args[2].toString());
                        param.args[2]=100000;
                    }
                    //方法执行后执行,改方法的返回值一定要在方法执行完毕后更改
                    protected void afterHookedMethod(MethodHookParam param)
                            throws Throwable {
                    }
                }
        );
    }
}
